package com.flca.frw.zk.validate;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.zkoss.zk.ui.Component;
import org.zkoss.zk.ui.WrongValueException;

import com.flca.frw.util.TransformUtils;
import com.flca.frw.validators.ValidationError;
import com.flca.frw.validators.Validator;

public class ValidateDateRange extends ValidateDateConstraintBase {

	private Date minDate;
	private Date maxDate;
	
	public ValidateDateRange(Date minDate, Date maxDate) 
	{
		super();
		this.minDate = minDate;
		this.maxDate = maxDate;
	}

	public void validate(Component aComp, Object aValue)
			throws WrongValueException 
	{
		List<ValidationError> errors = new ArrayList<ValidationError>();
		if (!Validator.testGreaterOrEquals(getTestDate(), minDate, errors, "", null)) {
			TransformUtils tu = TransformUtils.getInstance();
			String msg = "Datum te oud, minimum = " + tu.date2String(minDate); 
			throw new WrongValueException(aComp, msg);
		}
		if (!Validator.testSmallerOrEquals(getTestDate(), maxDate, errors, "", null)) {
			TransformUtils tu = TransformUtils.getInstance();
			String msg = "Datum te nieuw, mamimum = " + tu.date2String(maxDate); 
			throw new WrongValueException(aComp, msg);
		}
		
		
		
	}

}
